﻿package Interface.BattlesClasses
{
	import Interface.ArrowsScroller;	
	import GameUtils.BattleRequestData;
	
	import flash.events.MouseEvent;	
	import com.junkbyte.console.Cc;
	
	public class BattlesScroller extends ArrowsScroller
	{
		private var FContainer:BattlesContainer;
		
		public function BattlesScroller():void
		{
			super();
			FContainer = getChildByName('Container') as BattlesContainer;			
			FUp.enabled = false;
			FDown.enabled = FContainer.PagesCount > 0;
		}		
		
		public function Add(AData:BattleRequestData):BattleLabel
		{
			var vLabel:BattleLabel = FContainer.AddItem(AData);
			FDown.enabled = FContainer.PagesCount > 0;
			return vLabel;
		}
		
		public function Remove(AUID:String):void
		{
			FContainer.Remove(AUID);
			FDown.enabled = FContainer.PagesCount > 0;
		}
		
		public function Clear():void
		{
			FContainer.Clear();			
			FUp.enabled = false;
			FDown.enabled = false;
		}
		
		public function Update():void
		{
			FContainer.Update();
		}
		
		override protected function OnUp(e:MouseEvent):void
		{
			if (e.target.enabled)
			{				
				FContainer.MoveUp();
				FUp.enabled = !FContainer.IsFirstPage;
				FDown.enabled = !FContainer.IsLastPage;
			}
		}
		
		override protected function OnDown(e:MouseEvent):void
		{
			if (e.target.enabled)
			{				
				FContainer.MoveDown();
				FUp.enabled = !FContainer.IsFirstPage;
				FDown.enabled = !FContainer.IsLastPage;
			}
		}
	}	
}
